package com.thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author: may
 * @date: 2021年04月15日 22:23
 */
public class TestCachedThreadPool {
    public static void main(String[] args) {
        ExecutorService es = Executors.newCachedThreadPool();

        for (int i = 0; i < 3; i++) {
            es.execute(() -> {
                System.out.println(Thread.currentThread().getName());
            });
        }

        System.out.println(es);
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(es);
        es.shutdown();

        //try {
        //    TimeUnit.SECONDS.sleep(60);
        //} catch (InterruptedException e) {
        //    e.printStackTrace();
        //}
        //System.out.println(es);
    }
}
